package com.haoshuang.zhouzhoubang.ui.activity

import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.haoshuang.zhouzhoubang.databinding.ActivityEwPriceBinding
import com.haoshuang.zhouzhoubang.ui.adapter.EcAdapter
import com.haoshuang.zhouzhoubang.ui.vm.EwPriceViewModel
import com.lnkj.jialubao.ui.page.bean.EwBean2
import com.mufeng.libs.base.BaseVMActivity
import com.mufeng.libs.state.observeState
import com.mufeng.libs.utils.toast
import com.mufeng.libs.utils.view.clickWithTrigger


/**
 *  
 */
class EwPriceActivity : BaseVMActivity<EwPriceViewModel, ActivityEwPriceBinding>() {

    override fun initView(savedInstanceState: Bundle?) {
        binding.appBar.ivBack.clickWithTrigger { finish() }
        binding.appBar.tvTitle.text = "额外费用"
    }
    lateinit var adapter: EcAdapter
    var list= arrayListOf<EwBean2>()
    var order_id=0
    override fun initData() {
        order_id= intent.getIntExtra("order_id",0)
        vm.getData("order_id" to order_id)
        adapter= EcAdapter(list)
        binding.apply {
            rvList.layoutManager=LinearLayoutManager(this@EwPriceActivity)
            rvList.adapter=adapter
        }
    }

    override fun startObserve() {
        vm.getData.observeState(this) {
            onLoading { }
            onError { code, msg ->
                dismissLoading()
                if (code!="402"){
                    toast(msg)
                }


            }
            onSuccess {
                dismissLoading()
                if (it!=null){
                    list.clear()
                    list.addAll(it.list)
                    adapter.notifyDataSetChanged()
                }
            }
        }
    }

}